package com.example.service

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
import com.alibaba.android.arouter.launcher.ARouter
import com.example.base.path.RouterPath
import com.example.base.view.BaseFragment
import com.example.service.adapter.ServiceUIAdapter
import com.example.service.databinding.FragmentServiceBinding
import com.example.service.entity.ServiceUIEntity
import dagger.hilt.android.AndroidEntryPoint


@AndroidEntryPoint
class ServiceFragment : BaseFragment<FragmentServiceBinding>() {
    override fun getLayoutId(): Int =R.layout.fragment_service
    val serviceList: MutableList<ServiceUIEntity> = mutableListOf()
    val serviceUIAdapter = ServiceUIAdapter()
    override fun initView() {
        //UI数据
        mDataBinding.rvUi.adapter=serviceUIAdapter
        mDataBinding.rvUi.layoutManager= GridLayoutManager(requireContext(),3)

        //添加UI数据
        serviceList.clear()
        serviceList.add(ServiceUIEntity(R.drawable.parkmanager,"车辆管理"))
        serviceList.add(ServiceUIEntity(R.drawable.parkmanager2,"车位管理"))
        serviceList.add(ServiceUIEntity(R.drawable.visitor,"访客管理"))
        serviceList.add(ServiceUIEntity(R.drawable.repair_manager,"维修管理"))
        serviceList.add(ServiceUIEntity(R.drawable.notice_manager,"公告管理"))
        serviceList.add(ServiceUIEntity(R.drawable.pmlou1,"收银管理"))
        serviceList.add(ServiceUIEntity(R.drawable.pmlou2,"即时通讯"))
        serviceList.add(ServiceUIEntity(R.drawable.pmlou3,"设备管理"))
        serviceList.add(ServiceUIEntity(R.drawable.pmlou4,"房源信息"))
        serviceList.add(ServiceUIEntity(R.drawable.pmlou5,"物业报修"))
        serviceList.add(ServiceUIEntity(R.drawable.pmlou6,"巡检管理"))
        serviceList.add(ServiceUIEntity(R.drawable.pmlou7,"企业档案"))
        serviceUIAdapter.data.clear()
        serviceUIAdapter.data.addAll(serviceList)
        serviceUIAdapter.notifyDataSetChanged()
        serviceUIAdapter.setOnItemClickListener { adapter, view, position ->
            when(serviceUIAdapter.data[position].name){
                "车辆管理"->{
                    ARouter.getInstance().build("/car/CarActivity").navigation()
                }
                "设备管理"->{
                    ARouter.getInstance().build( "/device/DeviceActivity").navigation()
                }
                "房源信息"->{
                    ARouter.getInstance().build( "/house/HouseActivity").navigation()
                }
                "企业档案"->{
                    ARouter.getInstance().build(  "/enterprise/EnterpriseActivity").navigation()
                }
                "收银管理"->{
                    ARouter.getInstance().build("/cashier/CashierActivity").navigation()
                }
                "物业报修"->{
                    ARouter.getInstance().build("/repair/RepairActivity").navigation()
                }
                "巡检管理"->{
                    ARouter.getInstance().build("/drop/DropActivity").navigation()
                }
            }
        }

    }

}
